<?php
$keyword = htmlspecialbo($_GET['keyword']);
$keyword = str_replace('+',' ',$keyword);
$keyword = str_replace('%20',' ',$keyword);
$seo_meta = get_seo_meta(0,'categories','Kết quả tìm kiếm cho từ khóa '.$_GET['keyword'],'');
$array_result = array();
$array_search_type = array(1=>'Điện thoại di động',2=>'Máy tính bảng',3=>'Phụ kiện',4=>'Dịch vụ sửa chữa',5=>'Tin tức');
$list_products = db_array('SELECT pro_name,pro_alias,pro_type,pro_details,pro_view,pro_image 
                           FROM products 
                           WHERE pro_active = 1 AND pro_name LIKE "%'.$keyword.'%" OR pro_tags LIKE "%,'.$keyword.',%" OR pro_tags LIKE "%'.$keyword.',%" OR pro_tags LIKE "%,'.$keyword.'%"
                           LIMIT 20');
foreach($list_products as $product) {
   $arr = array();
   $arr['name'] = $product['pro_name'];
   $arr['alias'] = url_product_detail($product);
   $arr['type'] = $product['pro_type'];
   $arr['image'] = $product['pro_image'];
   $arr['des'] = cut_string(removeHTML($product['pro_details']),320);
   $arr['view'] = $product['pro_view'];
   $array_result[] = $arr;
}
$list_accessories = db_array('SELECT acc_name,acc_alias,acc_image,acc_details,acc_view 
                              FROM accessories 
                              WHERE acc_active = 1 AND acc_name LIKE "%'.$keyword.'%" OR acc_tags LIKE "%,'.$keyword.',%" OR acc_tags LIKE "%'.$keyword.',%" OR acc_tags LIKE "%,'.$keyword.'%"
                              LIMIT 5');
foreach($list_accessories as $product) {
   $arr = array();
   $arr['name'] = $product['acc_name'];
   $arr['alias'] = url_accessories_detail($product);
   $arr['type'] = 3;
   $arr['image'] = $product['acc_image'];
   $arr['des'] = cut_string(removeHTML($product['acc_details']),320);
   $arr['view'] = $product['acc_view'];
   $array_result[] = $arr;
}
$list_services = db_array('SELECT ser_name,ser_alias,ser_image,ser_details 
                           FROM services 
                           WHERE ser_active = 1 AND ser_name LIKE "%'.$keyword.'%" OR ser_tags LIKE "%,'.$keyword.',%" OR ser_tags LIKE "%'.$keyword.',%" OR ser_tags LIKE "%,'.$keyword.'%"
                           LIMIT 10');
foreach($list_services as $product) {
   $arr = array();
   $arr['name'] = $product['ser_name'];
   $arr['alias'] = url_services_detail($product);
   $arr['type'] = 4;
   $arr['image'] = $product['ser_image'];
   $arr['des'] = cut_string(removeHTML($product['ser_details']),320);
   $arr['view'] = 1;
   $array_result[] = $arr;
}
$list_news = db_array('SELECT new_title,new_alias,new_image,new_detail 
                        FROM news 
                        WHERE new_active = 1 AND new_title LIKE "%'.$keyword.'%" OR new_tags LIKE "%,'.$keyword.',%" OR new_tags LIKE "%'.$keyword.',%" OR new_tags LIKE "%,'.$keyword.'%"
                        LIMIT 5');
foreach($list_news as $product) {
   $arr = array();
   $arr['name'] = $product['new_title'];
   $arr['alias'] = url_news_detail($product['new_alias']);
   $arr['type'] = 5;
   $arr['image'] = $product['new_image'];
   $arr['des'] = cut_string(removeHTML($product['new_detail']),320);
   $arr['view'] = 1;
   $array_result[] = $arr;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi-VN" lang="vi-VN" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <link href="<?=DOMAIN?>/favicon.ico" type="image/x-icon" rel="shortcut icon"/>
   <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
   <?
   if(count($array_result) == 0) {
      ?>
      <meta name="robots" content="noindex,nofollow" />
      <title>Tìm kiếm từ khóa <?=$keyword?></title>
      <?
   }else {
      echo $seo_meta;
   }
   ?>
   <!-- css -->
   <link rel="stylesheet" type="text/css" href="/themes/css/base.css"/>
   <link rel="stylesheet" type="text/css" href="/themes/css/product.css"/>
   <link rel="stylesheet" type="text/css" href="/themes/css/mobile.css"/>

   <script type="text/javascript" src="/themes/js/jquery-1.9.0.min.js"></script>
   <script type="text/javascript" src="/themes/js/site.js"></script>
</head>
<body>
   <?php include 'view/view_header.php'?>
   <?php include 'view/view_tags.php'?>
   <?php include 'view/view_support.php'?>
   <?php include 'view/view_footer.php'?>
</body>
</html>